package common;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class LoginDetails {

	private static String path = "C:\\sql_2.txt";
	
	/**
	 * Gets sql login details from text file formatted
	 * ip
	 * datasource
	 * username
	 * password
	 * @return String[] with connection details in the same order as file
	 * @throws IOException can't read from file
	 */
	public static String[] getLoginDetails() throws IOException
	{
		String[] details = new String[4];
		try {
			BufferedReader br = new BufferedReader(new FileReader(path));
			for (int i = 0 ; i < 4 ; i++)
				if ((details[i] = br.readLine()) == null){
					br.close();
					throw new IOException("Error in password file");
				}
			br.close();
		} catch (FileNotFoundException e) {
			throw new IOException("Password file not found");
		} catch (IOException e) {
			throw e;
		}
		
		for(String detail : details){
			System.out.println(detail);
		}
		return details;
	}
}